package api

import (
	"gitee.com/aldrice/monitor/api/auth"
	"gitee.com/aldrice/monitor/api/common"
	"gitee.com/aldrice/monitor/api/monitor"
	"gitee.com/aldrice/monitor/api/user"
	"gitee.com/aldrice/monitor/internal/router"
	"github.com/labstack/echo/v4"
)

func RoutesAuth(g *echo.Group) {
	g.POST("/register", router.WrapHandler(auth.Register))
	g.POST("/login", router.WrapHandler(auth.Login))
}

func RoutesUser(g *echo.Group) {
	g.Use(common.JWT)
	g.GET("/info", router.WrapHandler(user.GetSelfInfo))
	g.GET("/users", router.WrapHandler(user.GetUsers))
}

func RoutesMonitor(g *echo.Group) {
	g.Use(common.JWT)

	// object
	g.POST("/object/token", router.WrapHandler(monitor.AddObject))
	g.POST("/object", router.WrapHandler(monitor.SignUpObject))
	g.PUT("/object", router.WrapHandler(monitor.EditObject))

	g.GET("/objects", router.WrapHandler(monitor.GetObjects))
	g.GET("/object/:id", router.WrapHandler(monitor.GetObject))

	// setting
	g.POST("/setting", router.WrapHandler(monitor.CreateSetting))
	g.PUT("/setting", router.WrapHandler(monitor.EditSetting))
	g.DELETE("/setting/:id", router.WrapHandler(monitor.DeleteSetting))

	g.GET("/setting/:id", router.WrapHandler(monitor.GetSetting))
	g.GET("/settings", router.WrapHandler(monitor.GetSettings))
	g.GET("/setting/methods", router.WrapHandler(monitor.GetMethods))

	// rule
	g.POST("/rule", router.WrapHandler(monitor.CreateRule))
	g.PUT("/rule", router.WrapHandler(monitor.EditRule))
	g.DELETE("/rule/:id", router.WrapHandler(monitor.DeleteRule))

	g.GET("/rule/:id", router.WrapHandler(monitor.GetRule))
	g.GET("/rules", router.WrapHandler(monitor.GetRules))
	g.GET("/rule/alarm_level", router.WrapHandler(monitor.GetAlarmLevel))
	g.GET("/rule/status", router.WrapHandler(monitor.GetStatus))
	g.GET("/rule/alarm_logs", router.WrapHandler(monitor.GetAlarmLogs))

	// rule-chart
	g.GET("/rule/alarm_logs/chart", router.WrapHandler(monitor.GetAlarmLogsChart))
	g.GET("/rule/alarm_logs/count", router.WrapHandler(monitor.GetAlarmCount))
	g.GET("/rule/alarm_logs/source", router.WrapHandler(monitor.GetAlarmSource))
	g.GET("/rule/alarm_logs/radar", router.WrapHandler(monitor.GetAlarmRadar))

	// metric
	g.POST("/metric", router.WrapHandler(monitor.CreateMetric))
	g.PUT("/metric", router.WrapHandler(monitor.EditMetric))

	g.GET("/metrics", router.WrapHandler(monitor.GetMetrics))
}
